package com.ourclass.app;

import java.util.List;

import com.ourclass.R;
import com.ourclass.adapter.AdapterAula;
import com.ourclass.model.Aula;
import com.ourclass.model.Diario;
import com.ourclass.model.Professor;
import com.ourclass.model.Teste;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class AulasActivity extends Activity implements OnItemClickListener{
	private ListView list;	
	public static Aula aulaSelecionada;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_aulas);

		chamarLista();
		carregaLista();
		
		TextView rotuloDisciplina = (TextView) findViewById(R.id.aulaDisciplina);
		TextView rotuloCurso = (TextView) findViewById(R.id.aulaCurso);
		TextView rotuloAulas = (TextView) findViewById(R.id.aulaAulas);
		
		rotuloDisciplina.setText(DiariosActivity.diarioSelecionado.getDisciplina().getNome());
		rotuloCurso.setText(DiariosActivity.diarioSelecionado.getDisciplina().getCurso());
		rotuloAulas.setText(DiariosActivity.diarioSelecionado.getDisciplina().getAlunosMatriculados().size() + "/" + DiariosActivity.diarioSelecionado.getDisciplina().getCargaHoraria());
		
		Button botaoRegistrar = (Button) findViewById(R.id.aulaRegistrar);
		botaoRegistrar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				irParaRegistrarAula();				
			}
		});
	}

	private void irParaRegistrarAula(){
		Intent it = new Intent(this,RegistrarAulaActivity.class);		
		this.startActivity(it);
	}
	
	private void carregaLista() {		
		try {			
			atualizarLista(DiariosActivity.diarioSelecionado.getAulasMinistradas());
		} catch (NullPointerException e) {
			// TODO: handle exception
			e.printStackTrace();
			System.out.println("Deu valor NULO em aula...");
		}
	}

	private void chamarLista() {
		// TODO Auto-generated method stub
		list = (ListView) findViewById(R.id.listAulas);
		list.setItemsCanFocus(false);
		list.setFocusable(true);
		list.setFocusableInTouchMode(true);
		list.setClickable(true);
		list.setOnItemClickListener((OnItemClickListener) this);
	}

	private void atualizarLista(List<Aula> list2) {
		AdapterAula adapter = new AdapterAula(this, R.layout.adapter_aulas, list2);
		list.setAdapter(adapter);
		}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}
	}
	
